package com.ziytek.web.citizen.service.impl;

import com.ziytek.web.citizen.constant.ServerConstant;
import com.ziytek.web.citizen.model.bean.BatteriesDetails;
import com.ziytek.web.citizen.model.bean.StageDataMap;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author fenghx
 * @version 1.0
 * @className CompletableFutureServiceImpl
 * Description:
 * @date 2024/3/27 13:27
 */

@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CompletableFutureServiceImpl {

    public List<BatteriesDetails> processData(List<StageDataMap> stageDataMapList) {
        if (CollectionUtils.isEmpty(stageDataMapList)) {
            return Collections.emptyList();
        }

        stageDataMapList = stageDataMapList.stream().filter(Objects::nonNull).collect(Collectors.toList());
        if (CollectionUtils.isEmpty(stageDataMapList)) {
            return Collections.emptyList();
        }

        List<BatteriesDetails> batteryInfoList = new ArrayList<>();
        for (var stage : stageDataMapList) {
            var b = new BatteriesDetails();
            b.setC(stage.getC());
            b.setV(stage.getV());
            b.setAt(stage.getAt());
            b.setCap(stage.getCap());
            b.setType(stage.getSetType());
            b.setCt(DateFormatUtils.format(stage.getCt(), ServerConstant.DATE_FORMAT));
//            b.setCt(DateFormatUtils.format(stage.getCt(), ServerConstant.DATE_FORMAT_TIME));
            batteryInfoList.add(b);
        }

        return batteryInfoList;
    }
}
